package org.example.dao.impl;

import org.example.dao.UserDao;
import org.example.entity.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDaoImpl implements UserDao {
    @Override
    public User selectByAccount(Connection conn, String account) throws SQLException {
        String sql = "select * from USER where ACCOUNT=?";
        PreparedStatement statement = conn.prepareStatement(sql);
        statement.setObject(1, account);
        ResultSet resultSet = statement.executeQuery();
        User user = null;
        if (resultSet.next()) {
            user = new User();
            user.setId(resultSet.getInt("ID"));
            user.setAccount(resultSet.getString("ACCOUNT"));
            user.setPassword(resultSet.getString("PASSWORD"));
            user.setUsername(resultSet.getString("USERNAME"));
            user.setRole(resultSet.getString("ROLE"));
            user.setStatus(resultSet.getInt("STATUS"));
        }
        return user;
    }
}
